package whf.survey.web;

import whf.framework.entity.AbstractEntity;
import whf.framework.util.StringUtils;
import whf.framework.web.struts.WebData;
import whf.framework.web.struts.WebDispatchAction;
import whf.framework.web.struts.WebForward;
import whf.survey.entity.Survey;
import whf.survey.entity.SurveyTopic;
import whf.survey.service.SurveyService;
import whf.survey.service.SurveyServiceImp;
import whf.survey.util.Constants;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-09-12
 */
public class SurveyTopicAction extends WebDispatchAction {

	@Override
	public WebForward prepareCreate(AbstractEntity webEntity, WebData data) throws Exception {
		long surveyId = data.getLongParameter("surveyId", 0);
		if(surveyId != 0){
			Survey survey = SurveyServiceImp.getSurveyService().findByPrimaryKey(surveyId);
			((SurveyTopic)webEntity).setSurvey(survey);
		}
		return super.prepareCreate(webEntity, data);
	}

	//查看调查主题
	public WebForward viewTopics(AbstractEntity webEntity, WebData data) throws Exception {
		SurveyService service = SurveyServiceImp.getSurveyService();
		long surveyId = data.getLongParameter("surveyId", 0);
		Survey survey = service.findByPrimaryKey(surveyId);
		if(StringUtils.equalsIgnoreCase(survey.getStatus(), Constants.SURVEY_STATUS_CREATED)){
			return list(webEntity, data);
		} else {
			webEntity.setWebMethod("answer");
			return data.forward("viewTopics");
		}
	}
} 